import React, { Component } from 'react'
import { Button } from 'antd'
import {getCategory} from '../apis'

export default class Xhr extends Component {
    constructor() {
        super();
        this.state = {
            data1: []
        }
    }
    async componentDidMount() {
        let res = await getCategory();
        this.setState({
            data1: res.data
        })
    }
    getData() {
        this.axios.get('http://localhost:3000/play/category')
        .then(res => {
            console.log(res);
            this.setState({
                data1: res.data
            })
        })
    }
    getData1() {
        fetch('http://localhost:3000/play/category')
        .then(res => res.json())
        .then(res => {
            console.log(11, res);
            // this.setState({
            //     data1: res.data
            // })
        })
    }
    render() {
        return (
            <div>
                {
                    this.state.data1.map((item,index) => {
                        return (
                            <p key={index}>{item.title}</p>
                        )
                    })
                }
                <Button onClick={() => this.getData()}>发请求</Button>
                <hr/>
                <Button onClick={() => this.getData1()}>发请求-fetch</Button>
            </div>
        )
    }
}
